package generator;

import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentException;

import junit.framework.TestCase;

/**
 * tests the compiler
 */
public class OpenOfficeDocManagerTest extends TestCase {

    public static void main(String[] args) {
        junit.swingui.TestRunner.run(OpenOfficeDocManagerTest.class);
    }

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
    }

    /*
     * @see TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public final void testRead115() throws IOException {
        OpenOfficeDoc doc = OpenOfficeDocManager.read("testing/generator/simple115.sxw");
        assertEquals("application/vnd.sun.xml.writer",doc.getMimetype());
		try {
			Document xmlDoc = OpenOfficeDocManager.getContentDocument(doc);
	        Dom4jOpenOfficeDoc d4j = new Dom4jOpenOfficeDoc(xmlDoc);
	        System.out.println("body 115 = " + d4j.getBody());
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}        
    }

    public final void testRead301() throws IOException {
    	OpenOfficeDoc doc = OpenOfficeDocManager.read("testing/generator/simple301.odt");
        assertEquals("application/vnd.oasis.opendocument.text",doc.getMimetype());
        System.out.println(doc.getContent());
		try {
			Document xmlDoc = OpenOfficeDocManager.getContentDocument(doc);
	        Dom4jOpenOfficeDoc d4j = new Dom4jOpenOfficeDoc(xmlDoc);
	        System.out.println("body 301 = " + d4j.getBody());
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}        
    }

    public final void testCreate301() throws IOException {
    	OpenOfficeDoc doc = new OpenOfficeDoc();
    	doc.setMimetype("application/vnd.oasis.opendocument.text");
    	OpenOfficeDocManager.write(doc,"testing/generator/simple301_gen.odt");
    }


}
